<?php
session_start(); //we need to call PHP's session object to access it through CI
class Home extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}

	function index()
	{
		if($this->session->userdata('admin')){
			$session_data = $this->session->userdata('admin');
			$this->data['title'] = 'Home';
			$this->data['username'] = $session_data['username'];
			$this->data['nama'] = $session_data['nama'];
			$this->data['type'] = $session_data['type'];
			$this->load->library('view');
			$this->view->set_menu('home');
			$this->view->set_portlet_title('Menu Admin');
			$this->view->set_portlet_style('portlet box red');
			$this->view->set_view('custom/dashboard');
			$this->view->show($this->data);
		}else{
			redirect('admin', 'refresh');
		}
	}

	function logout()
	{
		$this->session->unset_userdata('admin');
		session_destroy();
		redirect('admin', 'refresh');
	}

	function sample()
	{
		$this->load->helper('url');
		if($this->session->userdata('logged_in'))
		{
			$session_data = $this->session->userdata('logged_in');
			$data['title'] = 'Buat Soal';
			$data['username'] = $session_data['username'];
			$data['nama'] = $session_data['nama'];
			$this->load->view('header_admin', $data);
			$this->load->view('create_soal', $data);
			$this->load->view('footer_admin', $data);
		}
		else
		{
			//If no session, redirect to login page
			redirect('login', 'refresh');
		}

	}
	
	function sample_table()
	{
		$this->load->helper('url');
		if($this->session->userdata('logged_in'))
		{
			$session_data = $this->session->userdata('logged_in');
			$data['title'] = 'sample tabel';
			$data['username'] = $session_data['username'];
			$data['nama'] = $session_data['nama'];
			$this->load->view('header_admin', $data);
			$this->load->view('sample_table', $data);
			$this->load->view('footer_admin', $data);
		}
		else
		{
			//If no session, redirect to login page
			redirect('login', 'refresh');
		}

	}

	function sample_form()
	{
		$this->load->helper('url');
		if($this->session->userdata('logged_in'))
		{
			$session_data = $this->session->userdata('logged_in');
			$data['title'] = 'sample tabel';
			$data['username'] = $session_data['username'];
			$data['nama'] = $session_data['nama'];
			$this->load->view('header_admin', $data);
			$this->load->view('sample_form', $data);
			$this->load->view('footer_admin', $data);
		}
		else
		{
			//If no session, redirect to login page
			redirect('login', 'refresh');
		}

	}

	function sample_soal()
	{
		$this->load->helper('url');
		if($this->session->userdata('admin'))
		{
			$session_data = $this->session->userdata('admin');
			$data['title'] = 'sample tabel';
			$data['user'] = $session_data['user'];
			$data['nama'] = $session_data['nama'];
			$this->load->view('sample_soal', $data);
		}
		else
		{
			//If no session, redirect to login page
			redirect('login', 'refresh');
		}

	}

	
	}
?>